﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HienThi;
using BUS;


namespace GUI
{
    public partial class Form_BanHang_TV : UserControl
    {
        public Form_BanHang_TV()
        {
            InitializeComponent();
        }
        BanHangTVBUS bus = new BanHangTVBUS();
        private void Form_BanHang_TV_Load(object sender, EventArgs e)
        {
            List<ThanhVien> cbbtv = bus.LayBangThanhVien();
            cbbThanhVien.Properties.DataSource = cbbtv;
            cbbThanhVien.ItemIndex = 0;
            List<LoaiDonHang> cbbldh = bus.LayBangLoaiDH();
            cbbLoaiDonHang.Properties.DataSource = cbbldh;
            cbbLoaiDonHang.ItemIndex = 0;
            txtNgayDatHang.EditValue = DateTime.Now.ToShortDateString();
            txtTienNo.EditValue = 0;
            List<BanHangTVHienThi> grd = new List<BanHangTVHienThi>();
            grd = bus.LayBangBanHangTVHienThi();
            grdcontrolBanHangTV.DataSource = grd;
            txtTongTienCT.EditValue = 0;
            txtTongTienCT.Properties.ReadOnly = true;
            txtThue.EditValue = 0;
            txtThue.Properties.ReadOnly = true;
            txtTongTienTT.EditValue = 0;
            txtTongTienTT.Properties.ReadOnly = true;
        }

        private void grdviewBanHangTV_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName == "SoLuong")
            {
                int dong = e.RowHandle;
                float dongia = float.Parse(grdviewBanHangTV.GetRowCellValue(dong, "DonGia").ToString());
                int soluong = int.Parse(grdviewBanHangTV.GetRowCellValue(dong, "SoLuong").ToString());
                float thanhtien = soluong * dongia;
                grdviewBanHangTV.SetRowCellValue(dong, "ThanhTien", thanhtien.ToString());
                float tienct = float.Parse(txtTongTienCT.EditValue.ToString());
                tienct += thanhtien;
                double thue = tienct * 0.1;
                double tientt = tienct + thue;
                txtTongTienCT.EditValue = tienct.ToString();
                txtThue.EditValue = thue.ToString();
                txtTongTienTT.EditValue = tientt.ToString();

            }
        }

    }
}
